package com.brradish.todo.dao;

import java.util.List;

import javax.transaction.Transactional;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.brradish.todo.model.Person;

@Repository
@Transactional
public class PersonDAOImpl implements PersonDAO {
	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public void save(Person p) {
		Session session = this.sessionFactory.openSession();
		session.saveOrUpdate(p);
		session.flush();
	}

	@Override
	public List<Person> list() {
		Session session = this.sessionFactory.openSession();
		@SuppressWarnings("unchecked")
		List<Person> personList = session.createQuery("from Person").list();
		session.close();
		return personList;
	}

}
